package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoNewsPhone;
import com.muyu.danmo.service.IDanmoNewsPhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 新闻图片Controller
 *
 * @author yangle
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/phone")
public class DanmoNewsPhoneController extends BaseController
{
    @Autowired
    private IDanmoNewsPhoneService danmoNewsPhoneService;

    /**
     * 查询新闻图片列表
     */
//    @RequiresPermissions("system:phone:list")
    @PostMapping("/list")
    public Result<TableDataInfo<DanmoNewsPhone>> list(DanmoNewsPhone danmoNewsPhone)
    {
        startPage();
        List<DanmoNewsPhone> list = danmoNewsPhoneService.selectDanmoNewsPhoneList(danmoNewsPhone);
        return getDataTable(list);
    }

    /**
     * 导出新闻图片列表
     */
//    @RequiresPermissions("system:phone:export")
    @Log(title = "新闻图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoNewsPhone danmoNewsPhone)
    {
        List<DanmoNewsPhone> list = danmoNewsPhoneService.selectDanmoNewsPhoneList(danmoNewsPhone);
        ExcelUtil<DanmoNewsPhone> util = new ExcelUtil<DanmoNewsPhone>(DanmoNewsPhone.class);
        util.exportExcel(response, list, "新闻图片数据");
    }

    /**
     * 获取新闻图片详细信息
     */
//    @RequiresPermissions("system:phone:query")
    @GetMapping(value = "/{newsPhoneId}")
    public Result getInfo(@PathVariable("newsPhoneId") Long newsPhoneId)
    {
        return success(danmoNewsPhoneService.selectDanmoNewsPhoneByNewsPhoneId(newsPhoneId));
    }

    /**
     * 新增新闻图片
     */
//    @RequiresPermissions("system:phone:add")
    @Log(title = "新闻图片", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoNewsPhone danmoNewsPhone)
    {
        return toAjax(danmoNewsPhoneService.insertDanmoNewsPhone(danmoNewsPhone));
    }

    /**
     * 修改新闻图片
     */
//    @RequiresPermissions("system:phone:edit")
    @Log(title = "新闻图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoNewsPhone danmoNewsPhone)
    {
        return toAjax(danmoNewsPhoneService.updateDanmoNewsPhone(danmoNewsPhone));
    }

    /**
     * 删除新闻图片
     */
//    @RequiresPermissions("system:phone:remove")
    @Log(title = "新闻图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsPhoneIds}")
    public Result remove(@PathVariable Long[] newsPhoneIds)
    {
        return toAjax(danmoNewsPhoneService.deleteDanmoNewsPhoneByNewsPhoneIds(newsPhoneIds));
    }
}
